<template>
  <view class="player-container" v-if="show">
    <view class="player-content">
      <text class="playing-title">{{ playingItem.title }}</text>
      <view class="player-progress-container">
        <text class="player-time">{{ formatTime(sliderValue) }}</text>
        <wd-slider
          v-model="sliderValue"
          hide-min-max
          hide-label
          :min="0"
          :max="playingItem.duration"
          block-size="16"
          active-color="#5b8eff"
          inactive-color="#ebedf0"
          custom-style="flex: 1; height: 40rpx;"
          @dragend="onSeekChange"
        />
        <text class="player-time">{{ formatTime(playingItem.duration) }}</text>
      </view>
      <view class="player-controls">
        <wd-icon name="previous" size="25px" @click="onPrev" />
        <wd-icon :name="isPlaying ? 'pause' : 'play'" size="36px" @click="onToggle" />
        <wd-icon name="stop-circle-filled" size="30px" @click="onStop" />
        <wd-icon name="next" size="25px" @click="onNext" />
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
defineProps({
  playingItem: Object,
  isPlaying: Boolean,
  formatTime: Function,
  show: Boolean,
})

const sliderValue = defineModel<number>('sliderValue', { required: true, default: 0 })

const emit = defineEmits(['prev', 'next', 'toggle', 'stop', 'seek'])
const onSeekChange = ({ value }) => {
  emit('seek', value)
}
const onToggle = () => emit('toggle')
const onStop = () => emit('stop')
const onPrev = () => emit('prev')
const onNext = () => emit('next')
</script>

<style scoped>
.player-container {
  position: fixed;
  bottom: 100rpx;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 20rpx;
  border-top: 1px solid #eee;
  z-index: 100;
}

.player-content {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.playing-title {
  font-size: 30rpx;
  color: #333;
  font-weight: 500;
  margin-bottom: 15rpx;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90%;
}

.player-controls {
  display: flex;
  gap: 40rpx;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.player-progress-container {
  display: flex;
  align-items: center;
  width: 100%;
  margin: 15rpx 0 25rpx;
  gap: 20rpx;
}

.player-time {
  font-size: 26rpx;
  color: #666;
  min-width: 70rpx;
  text-align: center;
}
</style>
